﻿using System.Data;
using System.Diagnostics;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SharpCommon.Data;

namespace Test
{
    [TestClass]
    public class SQLServerHelperTest
    {
        [TestMethod]
        public void ExecuteNonQueryTest()
        {
            ParameterMappingInfo[] parameterMapping = 
            {
                new ParameterMappingInfo() { ParameterName = "@ID", ParameterValue = "88" },
                new ParameterMappingInfo() { ParameterName = "@name", ParameterValue = "aaaaaa" },
                new ParameterMappingInfo() { ParameterName = "@age", ParameterValue = 77 },
                new ParameterMappingInfo() { ParameterName = "@address", ParameterValue = "XXXXX" },
                new ParameterMappingInfo() { ParameterName = "@sex", ParameterValue = 1 },
            };
            DataBaseContext.DBInstance.ExecuteNonQuery("InsertPerson", parameterMapping);
        }

        [TestMethod]
        public void BatchInsertForMySQL()
        {
            ////SET SQL_SAFE_UPDATES=0;
            //DataTable dataTable = new DataTable("t_broker");
            //dataTable.Columns.Add(new DataColumn("name"));

            //for (int i = 1; i <= 10000; i++)
            //{
            //    DataRow dataRow = dataTable.NewRow();
            //    dataRow["name"] = "aaaaaa";
            //    dataTable.Rows.Add(dataRow);
            //}
            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();
            //DataBaseContext.DBInstance.BatchInsert(dataTable, "t_broker");
            //stopwatch.Stop();
            //Assert.Inconclusive(stopwatch.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture));

            string command = "SELECT * FROM upbaa_account.t_broker_trans;";
            DataBaseContext.DBInstance.ExecuteDataTable(command);
        }
    }
}
